import { createApp } from 'vue'
import { createPinia } from 'pinia'
import 'vant/es/toast/style'
import 'vant/es/notify/style'
import 'vant/es/dialog/style'
import 'vant/es/image-preview/style'
import App from './App.vue'
import router from './router'
import 'amfe-flexible'
function convertImgToBase64(url) {
  return new Promise((resolve) => {
    const canvas = document.createElement('CANVAS'),
      ctx = canvas.getContext('2d'),
      img = new Image()
    img.crossOrigin = 'anonymous'
    img.onload = function () {
      canvas.height = img.height
      canvas.width = img.width
      ctx.drawImage(img, 0, 0)
      resolve(canvas.toDataURL('image/png'))
    }
    img.src = `${url}?time=${+new Date()}`
  })
}

if (!window.android) {
  console.log('模拟安卓')
  const testImgUrl =
    'https://ghj-platform-file.recsteel.cn/test.all_in_one.weight.2024-09-13-13-38-56-832.121.112.jpg'
  convertImgToBase64(testImgUrl).then((testBase64) => {
    testBase64 = testBase64.split('base64,')[1]
    window.android = {
      getVersionName: () => '0.9',
      captureWebview: () => testBase64,
      getInspectData: () => {
        // 340521199608268542
        return `{"weight":"3.02","code":"788","type":"6","codeType":"A","file1":"${testBase64}","file2":"${testBase64}","file3":"${testBase64}","capture":"${testBase64}"}`
      },
      onRecognition: () => {},
      tts: () => {},
      getSystemConfig: console.log
    }
  })
}

const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')
